package com.ruoyi.hyg.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.hyg.mapper.FreeResourceMapper;
import com.ruoyi.hyg.domain.FreeResource;
import com.ruoyi.hyg.service.IFreeResourceService;

/**
 * 免费资料Service业务层处理
 *
 * @author ruoyi
 * @date 2025-08-13
 */
@Service
public class FreeResourceServiceImpl implements IFreeResourceService
{
    @Autowired
    private FreeResourceMapper freeResourceMapper;
    
    /**
     * 查询免费资料
     *
     * @param id 免费资料主键
     * @return 免费资料
     */
    @Override
    public FreeResource selectFreeResourceById(Long id) {
        FreeResource resource = freeResourceMapper.selectFreeResourceById(id);
        if (resource != null) {
            // 增加下载次数
            resource.setDownloadCount(resource.getDownloadCount() + 1);
            freeResourceMapper.updateFreeResource(resource);
        }
        return resource;
    }
    
    /**
     * 查询免费资料列表
     *
     * @param freeResource 免费资料
     * @return 免费资料
     */
    @Override
    public List<FreeResource> selectFreeResourceList(FreeResource freeResource)
    {
        return freeResourceMapper.selectFreeResourceList(freeResource);
    }
    
    /**
     * 新增免费资料
     *
     * @param freeResource 免费资料
     * @return 结果
     */
    @Override
    public int insertFreeResource(FreeResource freeResource) {
        freeResource.setCreateTime(DateUtils.getNowDate());
        freeResource.setDel(0L);  // 显式设置 del=0（未删除）
        return freeResourceMapper.insertFreeResource(freeResource);
    }
    
    /**
     * 修改免费资料
     *
     * @param freeResource 免费资料
     * @return 结果
     */
    @Override
    public int updateFreeResource(FreeResource freeResource)
    {
        return freeResourceMapper.updateFreeResource(freeResource);
    }
    
    /**
     * 批量删除免费资料
     *
     * @param ids 需要删除的免费资料主键
     * @return 结果
     */
    @Override
    public int deleteFreeResourceByIds(Long[] ids)
    {
        return freeResourceMapper.deleteFreeResourceByIds(ids);
    }
    
    /**
     * 删除免费资料信息
     *
     * @param id 免费资料主键
     * @return 结果
     */
    @Override
    public int deleteFreeResourceById(Long id)
    {
        return freeResourceMapper.deleteFreeResourceById(id);
    }
}
